<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

    <title>个人资料</title>

    <link href="${pageContext.request.contextPath}/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
    <link href="${pageContext.request.contextPath}/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet"
          type="text/css">

    <link href="${pageContext.request.contextPath}/css/personal.css" rel="stylesheet" type="text/css">
    <link href="${pageContext.request.contextPath}/css/infstyle.css" rel="stylesheet" type="text/css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/AmazeUI-2.4.2/assets/js/amazeui.js"></script>

    <style>
        .aui-info {
            position: relative;
        }

        .fileInput {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            opacity: 0;
            display: block;
            width: 100%;
            clear: both;
            display: block;
            margin: auto;
            background-color: red;
        }

    </style>
</head>
<body>
<!--头 -->
<header>
    <article>
        <div class="mt-logo">
            <!--顶部导航条 -->
            <div class="am-container header">
                <ul class="message-l">
                    <div class="topMessage">
                        <div class="menu-hd">
                        </div>
                    </div>
                </ul>
                <ul class="message-r">
                    <div class="topMessage home">
                        <div class="menu-hd"><a href="/home" target="_top" class="h">商城首页</a></div>
                    </div>
                    <div class="topMessage my-shangcheng">
                        <div class="menu-hd MyShangcheng"><a href="/personCenter" target="_top"><i
                                class="am-icon-user am-icon-fw"></i>个人中心</a></div>
                    </div>
                    <div class="topMessage mini-cart">
                        <div class="menu-hd"><a id="mc-menu-hd" href="/cartList" target="_top"><i
                                class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span></a>
                        </div>
                    </div>
                    <div class="topMessage favorite">
                        <div class="menu-hd"><a href="/toCollection" target="_top"><i
                                class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>
                    </div>
                </ul>
            </div>

            <!--悬浮搜索框-->

            <div class="nav white">
                <div class="logoBig">
                    <li><img src="../images/logobig.png"/></li>
                </div>

                <div class="search-bar pr">
                    <a name="index_none_header_sysc" href="#"></a>
                    <form action="/search" method="post">
                        <input id="searchInput" name="searchMsg" type="text" placeholder="搜索"
                               autocomplete="off">
                        <input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
                    </form>
                </div>
            </div>

            <div class="clear"></div>
        </div>
    </article>
</header>
<div class="nav-table">
    <div class="long-title"><span class="all-goods">全部分类</span></div>
    <div class="nav-cont">
        <ul>
            <li class="index"><a href="#">首页</a></li>
            <li class="qc"><a href="#">闪购</a></li>
            <li class="qc"><a href="#">限时抢</a></li>
            <li class="qc"><a href="#">团购</a></li>
            <li class="qc last"><a href="#">大包装</a></li>
        </ul>
        <div class="nav-extra">
            <i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
            <i class="am-icon-angle-right" style="padding-left: 10px;"></i>
        </div>
    </div>
</div>
<b class="line"></b>


<div class="center">
    <div class="col-main">
        <div class="main-wrap">

            <div class="user-info">
                <!--标题 -->
                <div class="am-cf am-padding">
                    <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">个人资料</strong> /
                        <small>Personal&nbsp;information</small>
                    </div>
                </div>
                <hr/>
                <%-- form表单 --%>
                <form:form action="/modInformation" method="post" class="am-form am-form-horizontal"
                           modelAttribute="userInformation" enctype="multipart/form-data">
                    <!--头像 -->
                    <div class="user-infoPic">
                        <div style="width:80px;height: 300px">
                                <%--                        <form:form action="/uploadPic" method="post" enctype="multipart/form-data">--%>

                            <div class="aui-info">
                                <img src="${userInformation.userProfile}" id="img-txz"
                                     style="width: 80px;height: 80px"
                                     class="am-circle am-img-thumbnail aui-img-round user-img"/>
                                <input type="file" accept="image/*" id="file-txz" name="uploadFile"
                                       style="width: 80px;height: 80px" form="formUpLoad"
                                       onchange="upload('#file-txz', '#img-txz');" class="fileInput"/><br>
                                    <%--                                <input align="center" type="submit" value="上传图片"/>--%>
                            </div>

                                <%--                        </form:form>--%>
                        </div>

                        <p class="am-form-help">头像</p>

                        <div class="info-m">
                            <div><b>用户名：<i>${userInformation.name}</i></b></div>
                            <div class="vip">
                                <span></span><a href="#">会员专享</a>
                            </div>
                        </div>
                    </div>
                    <%-- form表单 --%>
                    <%--                <form:form action="/modInformation" method="post" class="am-form am-form-horizontal"--%>
                    <%--                           modelAttribute="userInformation">--%>
                    <!--个人信息 -->
                    <div class="info-main">
                        <form:input type="hidden" path="userInfoId"/>
                        <form:input type="hidden" path="userId"/>
                        <form:input type="hidden" path="accountBalance"/>
                        <form:input type="hidden" path="totalPoints"/>
                        <form:input type="hidden" path="userProfile"/>
                        <div class="am-form-group">
                            <label for="user-name2" class="am-form-label">昵称</label>
                            <div class="am-form-content">
                                <form:input id="user-name2" placeholder="nickname" path="nickName" required="required"/>
                                    <%--                                       name="nickname" value="${userInformation.nickName}">--%>
                                <small>昵称长度不能超过40个汉字</small>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="user-name" class="am-form-label">姓名</label>
                            <div class="am-form-content">
                                <form:input id="user-name" placeholder="name" path="name" required="required"/>
                                    <%--                                       name="name" value="${userInformation.name}">--%>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">性别</label>
                            <div class="am-form-content sex">
                                <label class="am-radio-inline">
                                    <form:radiobutton path="gender" value="1" label="男"
                                                      class="data-am-ucheck"></form:radiobutton>

                                        <%--<input type="radio" name="radio10"  value="1" data-am-ucheck
                                            <c:if test="${userInformation.gender eq 1}">checked</c:if>
                                        /> 男--%>
                                </label>
                                <label class="am-radio-inline">
                                    <form:radiobutton path="gender" value="2" label="女"
                                                      class="data-am-ucheck"></form:radiobutton>

                                        <%--<input type="radio" name="radio10" value="2" data-am-ucheck
                                               <c:if test="${userInformation.gender eq 2}">checked</c:if>
                                        > 女--%>
                                </label>
                                <label class="am-radio-inline">
                                    <form:radiobutton path="gender" value="3" label="保密"
                                                      class="data-am-ucheck"></form:radiobutton>

                                        <%--<input type="radio" name="radio10" value="0" data-am-ucheck
                                               <c:if test="${userInformation.gender eq 0}">checked</c:if>
                                        > 保密--%>
                                </label>
                                    <%--<form:input path="gender" type="hidden"/>--%>
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="am-form-label">生日</label>
                            <div class="am-form-content birth">
                                <div class="birth-select">
                                    <select name="year" id="year" onchange="getDays()">
                                    </select>
                                    <em>年</em>
                                </div>
                                <div class="birth-select2">
                                    <select name="month" id="month" onchange="getDays()">
                                    </select>
                                    <em>月</em>
                                </div>
                                <div class="birth-select2">
                                    <select name="day" id="day">
                                    </select>
                                    <em>日</em>
                                </div>
                                <form:input type="hidden" path="birthday"/>
                            </div>

                        </div>
                        <div class="am-form-group">
                            <label for="user-phone" class="am-form-label">电话</label>
                            <div class="am-form-content">
                                <form:input id="user-phone" placeholder="telephonenumber" type="tel" path="phoneNum"
                                            pattern="^1[3|4|5|7|8][0-9]{9}$"/>
                                    <%--                                       name="phoneNum" value="${userInformation.phoneNum}">--%>

                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-email" class="am-form-label">电子邮件</label>
                            <div class="am-form-content">
                                <form:input id="user-email" placeholder="Email" type="email" path="email"/>
                                    <%--                                       name="email" value="${userInformation.email}">--%>
                            </div>
                        </div>
                        <div class="info-btn">
                            <div class="am-btn am-btn-danger"><input class="am-btn am-btn-danger" type="submit"
                                                                     value="保存修改"></div>
                        </div>
                    </div>
                </form:form>
            </div>
            <form action="/upload" method="post" enctype="multipart/form-data" id="formUpLoad">
            </form>

        </div>
        <!--底部-->
        <div class="footer">
            <div class="footer-hd">
                <p>
                    <b>|</b>
                    <a href="# ">商城首页</a>
                    <b>|</b>
                    <a href="# ">支付宝</a>
                    <b>|</b>
                    <a href="# ">物流</a>
                </p>
            </div>
            <div class="footer-bd ">
                <p>
                    <a href="# ">合作伙伴</a>
                    <a href="# ">联系我们</a>
                    <a href="# ">网站地图</a>
                </p>
            </div>
        </div>
    </div>

    <aside class="menu">
        <ul>
            <li class="person active">
                <a href="/personCenter"><i class="am-icon-user"></i>个人中心</a>
            </li>
            <li class="person">
                <p><i class="am-icon-newspaper-o"></i>个人资料</p>
                <ul>
                    <li><a href="/toInformation">个人信息</a></li>
                    <li><a href="/toSafety">安全设置</a></li>
                    <li><a href="/toAddress">地址管理</a></li>
                </ul>
            </li>
            <li class="person">
                <p><i class="am-icon-balance-scale"></i>我的交易</p>
                <ul>
                    <li><a href="/toOrder">订单管理</a></li>
                    <li><a href="/toComment">评价商品</a></li>
                </ul>
            </li>
            <li class="person">
                <p><i class="am-icon-tags"></i>我的收藏</p>
                <ul>
                    <li><a href="/toCollection">收藏</a></li>
                    <li><a href="/toFoot">足迹</a></li>
                </ul>
            </li>

            <li class="person">
                <p><i class="am-icon-qq"></i>在线客服</p>
                <ul>
                    <li><a href="/toConsultation">商品咨询</a></li>
                    <li><a href="/toSuggest">意见反馈</a></li>
                </ul>
            </li>
        </ul>
    </aside>
</div>
</body>
<script type="text/javascript">
    $(document).ready(function () {
        var date = new Date();//创建日期对象
        var year = date.getFullYear();//获取当前年份

        //初始化日期
        $("#year").append("<option value=\"" + ${year} +"\">" + ${year} +"</option>");
        for (var i = year - 100; i <= year; i++) {//在id为year的selector附加option选项
            $("#year").append("<option value=\"" + i + "\">" + i + "</option>");//append函数附加html到元素结尾处
        }
        $("#month").append("<option value=\"" + ${month} +"\">" + ${month} +"</option>");
        for (var i = 1; i <= 12; i++) {
            $("#month").append("<option value=\"" + i + "\">" + i + "</option>");//为Id为month的selector附加option选项
        }
        getDays($("#month").val(), $("#year").val());
    });

    function getDaysInMonth(month, year) {//年月对应的日数算法
        var days;
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            days = 31;//固定31
        } else if (month == 4 || month == 6 || month == 9 || month == 11) {
            days = 30;//固定30
        } else {
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { //排除百年，每四年一闰；每四百年一闰；
                days = 29; //闰年29
            } else {
                days = 28; //平年28
            }
        }
        return days;//返回该年月的日数
    }

    function getDays() {
        var year = $("#year").val();//year selector οnchange="getDays()"动态获取用户选择的year值
        var month = $("#month").val();//month selector οnchange="getDays()"动态获取用户选择的month值
        var days = getDaysInMonth(month, year);//调用算法函数计算对应年月的日数
        $("#day").empty();//调用empty()函数清空day selector options，然后再append函数往day selector添加options
        $("#day").append("<option value=\"" + ${day} +"\">" + ${day} +"</option>");
        for (var i = 1; i <= days; i++) {
            $("#day").append("<option value=\"" + i + "\">" + i + "</option>");
        }
    }

    $(function () {
        $("#year").change(function () {
            setDate();
        });
        $("#month").change(function () {
            setDate();
        });
        $("#day").change(function () {
            setDate();
        });
        // $("#radio10").change(function () {
        //     setGender();
        // });


        function setDate() {
            var year1 = $("#year").val();
            var month1 = $("#month").val();
            var day1 = $("#day").val();

            var oldTime = (new Date(year1 + "/" + month1 + "/" + day1));
            $("#birthday").attr("value", oldTime);
        }

        // function setGender() {
        //     alert("6666666666");
        // }
    })

    // // 找到头像的input标签绑定change事件
    // $("#id_avatar").change(function () {
    //     // 1. 创建一个读取文件的对象
    //     var fileReader = new FileReader();
    //     // 取到当前选中的头像文件
    //     // console.log(this.files[0]);
    //     // 读取你选中的那个文件
    //     fileReader.readAsDataURL(this.files[0]);  // 读取文件是需要时间的
    //     fileReader.onload = function () {
    //         // 2. 等上一步读完文件之后才 把图片加载到img标签中
    //         $("#avatar-img").attr("src", fileReader.result);
    //     };
    // });
    var upload = function (c, d) {
        "use strict";
        var $c = document.querySelector(c),
            $d = document.querySelector(d),
            file = $c.files[0],
            reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            $d.setAttribute("src", e.target.result);
        };
        $("#formUpLoad").submit();
    };
</script>

</html>
